import re

file = open("F:/awei/分析/提取出来的数据.txt")

lines = 1
x_1 = 0.0
y_1 = 0.0
z_1 = 0.0

x_2 = 0.0
y_2 = 0.0
z_2 = 0.0

dx = 0.0
dy = 0.0
dz = 0.0


for line in file:
    #print(line)
    ##偶数
    if(lines%2 == 0):
        if( line.find("反馈位置")>0 ):
            #print("")
            re1 = re.compile(r"X:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    x_1 = float(s2.group(0))
            else:
                print("X_1 ERROR")
                    
            re1 = re.compile(r"Y:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    y_1 = float(s2.group(0))
            else:
                print("Y_1 ERROR")

            re1 = re.compile(r"Z:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    z_1 = float(s2.group(0))
            else:
                print("Z_1 ERROR")
                    
        else:
            print("反馈位置不匹配")
            
    else:
        if( line.find("理论位置")>0 ):
            #print("")
            re1 = re.compile(r"X:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    x_2 = float(s2.group(0))
            else:
                print("X_2 ERROR")
                    
            re1 = re.compile(r"Y:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    y_2 = float(s2.group(0))
            else:
                print("Y_2 ERROR")

            re1 = re.compile(r"Z:[-\d\.\,]+")
            s1 = re1.search(line)
            if s1:
                re2 = re.compile(r"[-\d\.]+")
                s2 = re2.search( s1.group(0) )
                if s2 : 
                    #print(s2.group(0))
                    z_2 = float(s2.group(0))
            else:
                print("Z_2 ERROR")
        else:
            print("理论位置不匹配")

    if(lines%2 == 0):
        dx = x_1 - x_2
        dy = y_1 - y_2
        dz = z_1 - z_2
        print(x_1,";",x_2,";",y_1,";",y_2,";",z_1,";",z_2,";",dx,";",dy,";",dz,";")
    
        x_1 = 0.0
        y_1 = 0.0
        z_1 = 0.0

        x_2 = 0.0
        y_2 = 0.0
        z_2 = 0.0
    
    lines += 1

print(lines)
